/*
 * Attempt to solve the great escape problem
 */

#include "stdafx.h"
using namespace std;

typedef vector<int> intvector;
vector<intvector> connections;

struct node  {
	bool visited;
	int dist;
}* nodes;

void great_escape_main()  {
	int n; // number of buildings
	cin >> n;
	// initialize nodes
	nodes = new node[n];
	for(int i = 0; i < n; i++)  {
		nodes[i].visited = false;
		nodes[i].dist = -1;
	}

	int m; // number of connections
	cin >> m;

	connections.resize(n);

	// input connections
	for(int i = 0; i < m; i++)  {
		int start; int dest;
		cin >> start >> dest;
		connections[start-1].push_back(dest-1);
		connections[dest-1].push_back(start-1);
	}

	// input start, dest
	int start, dest;
	cin >> start >> dest;
	start--; dest--;

	nodes[start].dist = 0;
	nodes[start].visited = true;
	for(int i=0; i < n; i++)  {

		bool neighbour_found = false;
		for(int j = 0; j < n; j++)  {
			if(nodes[j].dist == i)  {
				int curr_node = j;
				if(curr_node == dest) { cout << nodes[curr_node].dist; return; }

				// for each node connected to this node
				for(int k=0; k < connections[curr_node].size(); k++)  {
					int next_node = connections[curr_node][k];
					if(!nodes[next_node].visited)  {
						nodes[next_node].dist = nodes[curr_node].dist + 1;
						nodes[next_node].visited = true;
						neighbour_found = true;
					}
				}
			}
		}
		if(!neighbour_found)  { cout << 0; return; }
	}

	delete [] nodes;
}